<?php
class Paper_sizes extends Controller{
    
    function Paper_sizes(){
        parent::Controller();
       
       $this->load->library('session');
	    if($this->session->userdata('admin') == '')
    	{
    		 redirect('admin');
    	}
         $this->load->helper(array('form','tiap_helper','html'));
       $this->load->library('form_validation'); 
         $this->load->model('paper_sizes_model');
    }
    
    
    function index(){
        
        	$data = array();
    	
		 $page = (int)$this->uri->segment(4);
		
		$page = ($page == '')?0:$page;
		
	   	$per_page = 15;
    	$data['total_paper_sizes'] = $this->paper_sizes_model->total_paper_sizes();
		// pagination start
		$this->load->library('pagination');
		$config['base_url'] = site_url('admin/paper_sizes/index/');
		$config['total_rows'] = $data['total_paper_sizes'];
		$config['per_page'] = $per_page;
	
		$config['uri_segment'] = 4;

		$this->pagination->initialize($config); 

		$data['pagination'] =  $this->pagination->create_links();
		//pagination end
    	$data['order_by'] = $order_by;
    	
        
      $data['paper_sizes']=$this->paper_sizes_model->list_paper_sizes($per_page,$page);  
       $data['page']=$page;
		$this->load->view(TEMPLATE_NAME.'/admin/paper_sizes/list',$data);
        
    }
    function detail(){
        
        	$data = array();
    	    $id = (int)$this->uri->segment(4);
            $page = (int)$this->uri->segment(5);
            $data['page']=$page;	
			$data['paper_sizes_detail']=$this->paper_sizes_model->get_paper_sizes_detail($id );
			$this->load->view(TEMPLATE_NAME.'/admin/paper_sizes/detail',$data);
        
    }
    function delete(){
		  
         $id=$this->input->post('papersizes');
          
         $check= $this->paper_sizes_model->delete_paper_sizes($id);
        
           redirect('admin/paper_sizes');
        
		}
        
   function form(){
		  
         	$data = array();
    	    $id = (int)$this->uri->segment(4);
             $page= (int)$this->uri->segment(5);
            $data['page']=$page;
            $data['paper_sizes_detail']=$this->paper_sizes_model->get_paper_sizes_detail($id );
			$this->load->view(TEMPLATE_NAME.'/admin/paper_sizes/action',$data);
        
		}
  function action(){
        $page= $this->input->post('page');
        $data['page']=$page;
         $this->form_validation->set_error_delimiters('<div class="error">','</div>');   
         $this->form_validation->set_rules('papersize_title','Paper size','required');
           $this->form_validation->set_rules('papersize_width','Paper width','required|numeric');
             $this->form_validation->set_rules('papersize_height','Paper height','required|numeric');
         $this->form_validation->set_message('required','Please enter %s');
          $this->form_validation->set_message('numeric','Please enter number value %s');
         if($this->form_validation->run() == False){
            $this->load->view(TEMPLATE_NAME.'/admin/paper_sizes/action',$data);
            }else{
            $this->paper_sizes_model->do_action();
            
             redirect('admin/paper_sizes/index/'.$page);
             }
        
		}
    
}
?>